home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 August: Tool Chest / Dev.CD Aug 95 TC / Dev.CD Aug 95 TC.toast / Tool Chest / Development Tools & Languages / Dylan Related / Marlais / Marlais 0.5.9-portable sources / sys.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-15  |  2.5 KB  |  116 lines  |  [TEXT/ttxt]

  1. /*
  2.  
  3.    sys.c
  4.  
  5.    This software is free software; you can redistribute it and/or
  6.    modify it under the terms of the GNU Library General Public
  7.    License as published by the Free Software Foundation; either
  8.    version 2 of the License, or (at your option) any later version.
  9.  
  10.    This software is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.    Library General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU Library General Public
  16.    License along with this software; if not, write to the Free
  17.    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19.    Original copyright notice follows:
  20.  
  21.    Copyright, 1994, Joseph N. Wilson.  All Rights Reserved.
  22.  
  23.    Permission to use, copy, and modify this software and its
  24.    documentation is hereby granted only under the following terms and
  25.    conditions.  Both the above copyright notice and this permission
  26.    notice must appear in all copies of the software, derivative works
  27.    or modified version, and both notices must appear in supporting
  28.    documentation.  Users of this software agree to the terms and
  29.    conditions set forth in this notice.
  30.  
  31.  */
  32.  
  33. #ifndef MACOS
  34. #include <sys/time.h>
  35. #else
  36. #include <time.h>
  37. #endif
  38.  
  39. #include "sys.h"
  40.  
  41. #include "bytestring.h"
  42. #include "error.h"
  43. #include "number.h"
  44. #include "prim.h"
  45. #include "values.h"
  46.  
  47. static struct primitive sys_prims[] =
  48. {
  49.     {"ctime", prim_0, get_ctime},
  50.     {"time", prim_0, get_time},
  51.     {"clock", prim_0, get_clock},
  52.     {"system", prim_1, user_system},
  53. };
  54.  
  55. void
  56. init_sys_prims (void)
  57. {
  58.     int num;
  59.  
  60.     num = sizeof (sys_prims) / sizeof (struct primitive);
  61.  
  62.     init_prims (num, sys_prims);
  63. }
  64.  
  65. Object
  66. get_ctime ()
  67. {
  68.     time_t time_loc;
  69.  
  70.     (void) time (&time_loc);
  71.     return make_byte_string (ctime (&time_loc));
  72. }
  73.  
  74. Object
  75. get_time ()
  76. {
  77.     time_t time_loc;
  78.  
  79.     (void) time (&time_loc);
  80.  
  81. #ifndef SMALL_OBJECTS
  82.     time_loc = abs ((int) time_loc);
  83. #else
  84.     time_loc = abs ((int) (time_loc << 2)) >> 2;
  85. #endif
  86.  
  87.     return make_integer (time_loc);
  88. }
  89.  
  90. Object
  91. get_clock ()
  92. {
  93.     clock_t clock_val;
  94.  
  95.     clock_val = clock ();
  96.  
  97. #ifndef SMALL_OBJECTS
  98.     clock_val = abs ((int) clock_val);
  99. #else
  100.     clock_val = abs ((int) (clock_val << 2)) >> 2;
  101. #endif
  102.  
  103.     return make_integer (clock_val);
  104. }
  105.  
  106. Object
  107. user_system (Object string)
  108. {
  109.     if (!BYTESTRTYPE (string)) {
  110.     error ("system: argument must be a string", string, NULL);
  111.     } else {
  112.     return make_integer (system (BYTESTRVAL (string)));
  113.  
  114.     }
  115. }
  116.